import 'package:flutter/material.dart';
import 'package:p_location/common/widget/tag_view.dart';
import 'package:p_location/home/obj/area_car_obj.dart';
import 'package:p_location/home/ui/vehicle/page_inner_car_detail.dart';
import 'package:p_location/home/ui/vehicle/page_outer_car_detail.dart';
import 'package:p_location/map/jaguar_demo.dart';
import 'package:p_location/map/res/search_person_detail.dart';
import 'package:p_location/map/ui/page_person_trace.dart';
import 'package:p_location/utils/navigator_util.dart';

class CellAreaCarInfo extends StatelessWidget {
  final AreaCarObj _carObj;

  const CellAreaCarInfo(this._carObj);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        if (_carObj.type == "外来车辆") {
          NavigatorUtil.push(
              context, PageOuterCarDetail(_carObj.id, _carObj.carNum,carObj: _carObj,));
        } else if (_carObj.type == "内部车辆") {
          NavigatorUtil.push(
              context, PageInnerCarDetail(_carObj.id, _carObj.carNum));
        }
      },
      child: Container(
        color: Colors.transparent,
        child: Stack(
          alignment: Alignment.centerLeft,
          children: <Widget>[
            Card(
              margin: EdgeInsets.only(left: 10, right: 10, top: 10),
              child: Row(
                children: [
                  Container(
                    width: 120,
                    height: 100,
                    alignment: Alignment.center,
                    margin: EdgeInsets.only(left: 10),
                    decoration: BoxDecoration(
                        borderRadius: BorderRadius.all(Radius.circular(6)),
                        gradient: LinearGradient(
                            //渐变位置
                            begin: Alignment.topRight, //右上
                            end: Alignment.bottomLeft, //左下
                            stops: [
                              0.0,
                              1.0
                            ], //[渐变起始点, 渐变结束点]
                            //渐变颜色[始点颜色, 结束颜色]
                            colors: [
                              Color.fromRGBO(56, 160, 253, 0.9),
                              Color.fromRGBO(26, 103, 250, 0.9)
                            ])),
                    child: Text(
                      _carObj.carNum,
                      style: TextStyle(color: Colors.white, fontSize: 20),
                    ),
                  ),
                  Container(
                    height: 120,
                    margin: EdgeInsets.only(left: 15),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: <Widget>[
                        Text(
                          '${_carObj.carNum}(${_carObj.type})',
                          style: TextStyle(
                            fontSize: 16,
                          ),
                        ),
                    Container(
                      constraints: BoxConstraints(
                        maxWidth: 250,
                        minWidth: 200,
                      ),
                      child:Text(
                          '驾驶员：${_carObj.driverName} 速度：${_carObj.speed}km/h',
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                          style: TextStyle(fontSize: 14, color: Colors.grey),
                        ),
                    ),
                        Wrap(
                          children: [
                            TagView(
                              "实时跟踪",
                              paddingLeft: 10,
                              paddingRight: 10,
                              paddingTop: 3,
                              paddingBottom: 3,
                              radius: 5,
                              strokeColor: Color.fromARGB(255, 56, 160, 253),
                              textColor: Color.fromARGB(255, 56, 160, 253),
                              fillColor: Colors.white,
                              onPress: () {
                                SearchPersonDetail detail =
                                    SearchPersonDetail();
                                detail.id = _carObj.id;
                                detail.name = _carObj.carNum;
                                detail.sn = _carObj.vehicleSn;
                                detail.typeName = _carObj.type;
                                NavigatorUtil.push(
                                    context,
                                    GisMapPage(
                                      realTrackTarget: detail,
                                    ));
                              },
                            ),
                            Container(
                              margin: EdgeInsets.only(left: 5),
                              child: TagView("查询轨迹",
                                  paddingLeft: 10,
                                  paddingRight: 10,
                                  paddingTop: 3,
                                  paddingBottom: 3,
                                  radius: 5,
                                  strokeColor:
                                      Color.fromARGB(255, 56, 160, 253),
                                  textColor: Color.fromARGB(255, 56, 160, 253),
                                  fillColor: Colors.white, onPress: () {
                                SearchPersonDetail detail =
                                    SearchPersonDetail();
                                detail.id = _carObj.id;
                                detail.name = _carObj.carNum;
                                detail.sn = _carObj.vehicleSn;
                                detail.typeName = _carObj.type;
                                NavigatorUtil.push(
                                    context,
                                    PagePersonTrace(
                                        isSingleTrace: true, chosenSn: detail));
                              }),
                            )
                          ],
                        )
                      ],
                    ),
                  )
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}
